﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sql_Dataprovider;
using System.Data;
using System.Data.SqlClient;

namespace DACK_N28_QLRCP
{
    class PhongChieu
    {
        private int _maPC;
        public int MaPhongChieu
        {
            get { return _maPC; }
            set { _maPC = value; }
        }
        private int _maRap;
        public int MaRap
        {
            get { return _maRap; }
            set { _maRap = value; }
        }
        private int _soHangGhe;
        public int SoHangGhe
        {
            get { return _soHangGhe; }
            set { _soHangGhe = value; }
        }
        private int _soDayGhe;
        public int SoDayGhe
        {
            get { return _soDayGhe; }
            set { _soDayGhe = value; }
        }
        private string _moTa;
        public string MoTa
        {
            get { return _moTa; }
            set { _moTa = value; }
        }
        private int _maDKKT;
        public int MaDieuKienKT
        {
            get { return _maDKKT; }
            set { _maDKKT = value; }
        }
        private string _tinhTrang;
        public string TinhTrang
        {
            get { return _tinhTrang; }
            set { _tinhTrang = value; }
        }
    }
    class PhongChieu_DAO
    {
        public static Boolean ThemPC (PhongChieu pc)
        {
            Sql_DataProvider Insert = new Sql_DataProvider();
            string sql = string.Format("InSert_PC");
            SqlParameter[] pr ={
                                 new SqlParameter("@marap", pc.MaRap),
                                 new SqlParameter("@sodayghe", pc.SoDayGhe),
                                 new SqlParameter("@sohangghe", pc.SoHangGhe),
                                 new SqlParameter("@mota", pc.MoTa),
                                 new SqlParameter("@makt", pc.MaDieuKienKT),
                                 new SqlParameter("@tinhtrang", pc.TinhTrang)
                               };
            SqlCommand cmd = new SqlCommand(sql);
            cmd.CommandType=CommandType.StoredProcedure;
            for (int i = 0; i < pr.Count(); i++)
            {
                cmd.Parameters.Add(pr[i]);
            }
            return Insert.SQL_ExecuteNonQuery(cmd);
        }
        public static Boolean SuaPC(PhongChieu PcUpdate)
        {
            Sql_DataProvider Update = new Sql_DataProvider();
            string sql = string.Format("Update_PhongChieu");
            SqlParameter[] pr ={    new SqlParameter("@MaPC", PcUpdate.MaPhongChieu),
                                 new SqlParameter("@MaRap", PcUpdate.MaRap),
                                 new SqlParameter("@SoDayGhe", PcUpdate.SoDayGhe),
                                 new SqlParameter("@SoHangGhe", PcUpdate.SoHangGhe),
                                 new SqlParameter("@MoTa", PcUpdate.MoTa),
                                 new SqlParameter("@MaDKKT", PcUpdate.MaDieuKienKT),
                                 new SqlParameter("@TinhTrang", PcUpdate.TinhTrang)
                               };
            SqlCommand cmd = new SqlCommand(sql);
            cmd.CommandType = CommandType.StoredProcedure;
            for (int i = 0; i < pr.Count(); i++)
            {
                cmd.Parameters.Add(pr[i]);
            }
            return Update.SQL_ExecuteNonQuery(cmd);
        }
        public static Boolean XoaPC(int id)
        {
            Sql_DataProvider Remove = new Sql_DataProvider();
            string sql = string.Format("Remove_PhongChieu");
            SqlParameter pr = new SqlParameter("@id", id);
            SqlCommand cmd = new SqlCommand(sql);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(pr);
            return Remove.SQL_ExecuteNonQuery(cmd);
        }
        public static PhongChieu Get_PC(int maPC)
        {
            PhongChieu pc = new PhongChieu();
            string sql = "select * from PhongChieu where MaPhongChieu =" + maPC;
            Sql_DataProvider GetPC = new Sql_DataProvider();
            SqlDataReader reader = GetPC.SQL_ExcuteQueryReader(sql);
            if (reader.Read())
            {
                pc.MaRap = Convert.ToInt32(reader["MaRap"]);
                pc.MaPhongChieu = Convert.ToInt32(reader["MaPhongChieu"]);
                pc.SoHangGhe = Convert.ToInt32(reader["SoHangGhe"]);
                pc.SoDayGhe = Convert.ToInt32(reader["SoDayGhe"]);
                pc.MaDieuKienKT = Convert.ToInt32(reader["MaDieuKienKiThuat"]);
                pc.MoTa = reader["MoTa"].ToString();
                pc.TinhTrang = reader["TinhTrang"].ToString();
            }
            return pc;
        }
    }
}
